# 用于读取文件的函数
def read_file(path, encoding="UTF-8"):
    with open(path, mode="r", encoding=encoding) as f:
        # 去掉后面的换行符并返回
        return [line.rstrip() for line in f.readlines()]


# 统计性别的人数
def sex_num(students):
    # 取出性别
    sexs = [stu.split(",")[3] for stu in students]

    # 统计性别的人数
    sex_num = {}
    for sex in sexs:
        if sex in sex_num:
            sex_num[sex] = sex_num[sex] + 1
        else:
            sex_num[sex] = 1

    # 返回结果
    return sex_num


# main: python程序的入口
if __name__ == '__main__':
    # 读取文件
    students = read_file("../../data/students.txt")

    # 统计性别的人数
    sex_n = sex_num(students)

    print(sex_n)
